package com.base.po.musk_sdk;

import org.bouncycastle.jce.provider.BouncyCastleProvider;

import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import java.nio.charset.StandardCharsets;
import java.security.Security;

/**
 * 常量
 */
public class MuskConstants {

    public static String ACCESSKEY = "kH8djDdxk8djgJHdkcj2439JHdkad39HJxHdsd";// 参数key
    public static String SECRETKEY = "J1HGda65JKdjdjdzxkfFdkeZ098ajKHdkxldrK";// 加密key

    public static final String CALL_AWARD = "http://116.62.244.67:8080/musk-thirteen-frontend/call/award";// 充值话费返币
    public static final String CALL_EXCHANGEMUSK = "http://116.62.244.67:8080/musk-thirteen-frontend/call/exchangeMusk";// 话费兑换币
    public static final String CALL_EXCHANGECHARGE= "http://116.62.244.67:8080/musk-thirteen-frontend/call/exchangeCharge";// 币兑换话费

    public static String encrytSHA256(String content, String secret) {
        String sign = null;

        try {
            Security.addProvider(new BouncyCastleProvider());
            SecretKey secretKey = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
            Mac mac = Mac.getInstance(secretKey.getAlgorithm());
            mac.init(secretKey);
            byte[] digest = mac.doFinal(content.getBytes(StandardCharsets.UTF_8));
            sign = new HexBinaryAdapter().marshal(digest).toLowerCase();
            return sign;
            // .toLowerCase()小写
            // .toUpperCase();大写
        } catch (Exception e) {
            return sign;
        }
    }
}
